package com.lheia.jcb

import common.HttpMesConstants
import grails.converters.JSON

class SpiderController {
    def spiderCreate(){}
    def spiderIndex(){}
    def spiderService

    /**
     * 爬虫管理表列表显示
     */
    def spiderQuery() {
        def dataMap = spiderService.spiderQuery(params)
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, count: dataMap.total, data: dataMap.data] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DATA_NULL] as JSON)
        }
    }
    /**
     * 爬虫管理表详情
     * @return
     */
    def getSpiderDataMap() {
        def dataMap = spiderService.getSpiderDataMap(params.long('spiderId'))
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, data: dataMap] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DATA_NULL] as JSON)
        }
    }

    /**
     * 爬虫管理表保存
     * @return
     */
    def spiderSave() {
        def dataMap = spiderService.spiderSave(params)
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_SAVE_OK, data: dataMap] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_SAVE_FAIL] as JSON)
        }
    }

    /**
     * 爬虫管理表删除
     * @return
     */
    def spiderDel() {
        def dataMap = spiderService.spiderDel(params.long('spiderId'))
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_DEL_OK] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DEL_FAIL] as JSON)
        }
    }

    def spiderRun(){
        def dataMap = spiderService.spiderRun(params.long('spiderId'))
        if (dataMap) {
            render([code: HttpMesConstants.CODE_OK, msg: HttpMesConstants.MSG_DEL_OK] as JSON)
        } else {
            render([code: HttpMesConstants.CODE_FAIL, msg: HttpMesConstants.MSG_DEL_FAIL] as JSON)
        }
    }
}


